﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.TokenDescriptor
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Security.Cryptography;
using System.Xml;

namespace Microsoft.InfoCards
{
  internal class TokenDescriptor : IDisposable
  {
    private string m_tokenId;
    private DateTime m_effectiveTime;
    private DateTime m_expirationTime;
    private XmlElement m_protectedToken;
    private DisplayToken m_displayToken;
    private SymmetricAlgorithm m_symmetricProof;
    private string m_internalTokenReference;
    private string m_externalTokenReference;
    private List<string> m_disclosedClaims;
    private bool m_disposed;
    private object m_sync;

    public TokenDescriptor(
      string tokenId,
      DateTime effectiveTime,
      DateTime expirationTime,
      XmlElement protectedToken,
      DisplayToken displayToken,
      SymmetricAlgorithm symmetricProof,
      string internalTokenReference,
      string externalTokenReference,
      IEnumerable<string> disclosedClaims)
    {
      this.m_sync = new object();
      this.m_tokenId = tokenId;
      this.m_effectiveTime = effectiveTime;
      this.m_expirationTime = expirationTime;
      this.m_protectedToken = protectedToken;
      this.m_displayToken = displayToken;
      this.m_symmetricProof = symmetricProof;
      this.m_internalTokenReference = internalTokenReference;
      this.m_externalTokenReference = externalTokenReference;
      this.m_disclosedClaims = new List<string>(disclosedClaims);
    }

    public ReadOnlyCollection<string> DisclosedClaims
    {
      get
      {
        return this.m_disclosedClaims.AsReadOnly();
      }
    }

    public string TokenId
    {
      get
      {
        return this.m_tokenId;
      }
    }

    public DateTime EffectiveTime
    {
      get
      {
        return this.m_effectiveTime;
      }
    }

    public DateTime ExpirationTime
    {
      get
      {
        return this.m_expirationTime;
      }
    }

    public string InternalTokenReference
    {
      get
      {
        return this.m_internalTokenReference;
      }
    }

    public string ExternalTokenReference
    {
      get
      {
        return this.m_externalTokenReference;
      }
    }

    public XmlElement ProtectedToken
    {
      get
      {
        return this.m_protectedToken;
      }
    }

    public DisplayToken DisplayToken
    {
      get
      {
        return this.m_displayToken;
      }
    }

    public SymmetricAlgorithm SymmetricProof
    {
      get
      {
        return this.m_symmetricProof;
      }
    }

    public void Write(BinaryWriter bwriter)
    {
      bwriter.Write(this.m_effectiveTime.ToFileTimeUtc());
      bwriter.Write(this.m_expirationTime.ToFileTimeUtc());
      Utility.SerializeString(bwriter, this.m_protectedToken.OuterXml);
      Utility.SerializeString(bwriter, this.m_internalTokenReference);
      Utility.SerializeString(bwriter, this.m_externalTokenReference);
    }

    public void Dispose()
    {
      if (this.m_disposed)
        return;
      lock (this.m_sync)
      {
        if (this.m_disposed)
          return;
        this.m_disposed = true;
        if (this.m_symmetricProof != null)
        {
          ((IDisposable) this.m_symmetricProof).Dispose();
          this.m_symmetricProof = (SymmetricAlgorithm) null;
        }
        this.m_protectedToken = (XmlElement) null;
        this.m_expirationTime = DateTime.MinValue;
        this.m_effectiveTime = DateTime.MinValue;
        this.m_tokenId = (string) null;
        this.m_externalTokenReference = (string) null;
        this.m_internalTokenReference = (string) null;
        this.m_disclosedClaims = (List<string>) null;
        this.m_displayToken = (DisplayToken) null;
      }
    }
  }
}
